package com.hucc.api.controller;

import com.hucc.api.domain.res.ApiResult;
import com.hucc.api.service.OpenApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huguocai
 */
@Api("openapi")
@Slf4j
@RestController
@RequestMapping("/openapi")
public class OpenApiController {
    @Autowired
    OpenApiService openApiService;

    @ApiOperation("收集swagger文档")
    @PostMapping("collectSwaggerDoc")
    public ApiResult<Void> collectSwaggerDoc(@RequestBody String doc) {
        try {
            openApiService.collectSwaggerDoc(doc);
            return ApiResult.success();
        } catch (Exception e) {
            log.error("collectSwaggerDoc error, doc: {}", doc, e);
            return ApiResult.fail("接收Swagger文档失败");
        }
    }
}
